<?php
	require('../../inc/config.php');
	if (!isset($_SESSION["admin"])) { die('Hacking attempt!!'); }
	
	//include(RADMIN.'/header-scripts.php');

	$id = request('id',0);
	$lista_id = request('lista_id',0);

	//-----------------------------------------------------------------------------------
	//                                                                  Ficha del Usuario
	//-----------------------------------------------------------------------------------	
	$sql = "select * from suscriptores where id='$id'";
	$rs  = $db->SelectLimit($sql,1);
	$data = $rs->FetchRow();
	$listas = explode(',',$data['listas']);
	
	
	//------------------------------------------------------------------------------------
	//                                                                 Listas de Correo
	//------------------------------------------------------------------------------------
	$sql = "select * from listas_correos where activo='1' order by nombre asc";
	$rs  = $db->Execute($sql);
	$Listas = $rs->GetRows();
	
?>
<style>
.control-label{
	font-size:12px;
}
</style>

<form method='post' action='<?php echo ADMIN;?>newsletter/suscriptores.php?accion=guardar&letra=<?php echo $letra;?>' 
	class="form-horizontal" role="form"  style='margin:10px;' enctype="multipart/form-data">	  

	<h2>Editar o Crear un Usuario</h2>
			<table style='width:100%;margin:10px;'>
			<tr>
			<td style='width:50%;border-right:1px solid #DDD;padding-right:5px;'>
				<div class="form-group">
					<label class="col-sm-3 control-label" for="email">Email(*):</label>
					<div class="col-sm-9">
						<input type="email" class="form-control" name='data[email]' id="inputEmail" required value='<?php echo $data['email'];?>'>
					</div>
				</div>

				<div class="form-group">
					<label class="col-sm-3 control-label" for="nombre">Nombre(*):</label>
					<div class="col-sm-9">
						<input type="text"  class="form-control" name='data[nombre]' id="nombre" required value='<?php echo $data['nombre'];?>'>
					</div>
				</div>

				
			</td>
			<td style='width:50%;vertical-align:top;padding-left:20px;'>
				
				
				<div class="form-group">
					<div class="col-sm-8">Lista de Correo:
						<select name='data[listas][]' id='listas' required class="form-control" multiple class="form-control">
							<?php foreach ($Listas as $l){?>
								<?php $sel = iif( in_array($l['id'],$listas),'selected','');?>
								<option value='<?php echo $l['id'];?>' <?php echo $sel;?> ><?php echo $l['nombre'];?></option>
							<?php } ?>
						</select>
						<span class="help-block">Ctrl+Click para seleccion multiple.</span>
					</div>
				</div>
			
			</td>
			</tr>
			</table>		

	<center>
	<br>
	<input type="hidden" name='data[id]' id="id" value='<?php echo $data['id'];?>'>	
	<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-sign-out"></i> Salir sin Guardar</button>
	<button type="submit" class="btn btn-primary" ><i class="fa fa-floppy-o"></i> Guardar Cambios</button>
	</center>
</form>